package com.rfs.design.chain.test;

import com.rfs.design.chain.ProcessController;
import com.rfs.design.chain.ProcessTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author renfushuai
 * @date 2022/8/29
 */
@Configuration
public class ChainConfig {
    @Autowired
    private PreParamCheckAction preParamCheckAction;
    @Autowired
    private AfterParamCheckAction afterParamCheckAction;
    @Autowired
    private SendMsgAction sendMsgAction;
    @Autowired
    private AfterSendMsgAction afterSendMsgAction;

    @Bean
    public ProcessTemplate sendMsgTemplate() {
        ProcessTemplate processTemplate = new ProcessTemplate();
        processTemplate.setProcessList(Arrays.asList(preParamCheckAction, afterParamCheckAction, sendMsgAction,afterSendMsgAction ));
        return processTemplate;
    }

    /**
     * 责任链流程控制器
     * 后续扩展则加ProcessTemplate
     *
     * @return
     */
    @Bean
    public ProcessController processController() {
        ProcessController processController = new ProcessController();
        Map<String, ProcessTemplate> templateConfig = new HashMap<>(4);
        templateConfig.put("sendMsg", sendMsgTemplate());
        processController.setTemplateConfig(templateConfig);
        return processController;
    }
}
